
package com.carsite.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.carsite.dao.DepartmentDao;
import com.carsite.model.Department;
import com.carsite.service.DepartmentManager;

public class DepartmentManagerImpl extends BaseManager implements DepartmentManager {
    private DepartmentDao dao;

    /**
     * Set the Dao for communication with the data layer.
     * @param dao
     */
    public void setDepartmentDao(DepartmentDao dao) {
        this.dao = dao;
    }

    /**
     * @see com.carsite.service.DepartmentManager#getDepartments(com.carsite.model.Department)
     */
    public List getDepartments(final Department department) {
        return dao.getDepartments(department);
    }

    /**
     * @see com.carsite.service.DepartmentManager#getDepartment(String deptId)
     */
    public Department getDepartment(final String deptId) {
        return dao.getDepartment(new Long(deptId));
    }

    /**
     * @see com.carsite.service.DepartmentManager#saveDepartment(Department department)
     */
    public void saveDepartment(Department department) {
        dao.saveDepartment(department);
    }

    /**
     * @see com.carsite.service.DepartmentManager#removeDepartment(String deptId)
     */
    public void removeDepartment(final String deptId) {
        dao.removeDepartment(new Long(deptId));
    }

	public Map getDeptsByBranch(String branchId) {
		List list = dao.getDeptsByBranch(branchId);
		Map map = new HashMap();
		 for (int i = 0; i < list.size(); i++) {
            Department dept = (Department) list.get(i);
            String deptId= dept.getDeptId().toString();
            String deptName= dept.getDeptName();
           
            map.put(deptId,deptName);
        }

        return map;
	}
	//得到仓库部门
	public List<Department> getWarehouse(){
		return dao.getWarehouse();
	}
}
